Personal tools

Lua/Events/Shared/NetworkObjectValueChange

From JC2-MP Documentation

< Lua
Jump to: navigation, search
Name    NetworkObjectValueChange
Arguments (in table)    object object, string key, object value
Return option    None


Description

Fired when EntityStorageBase:SetNetworkValue is called from any module on the server. It is not fired by calling EntityStorageBase:SetValue.

Example

Server

Use '/set playername key value' to set players' values on both server and client.

function Foo(args)
	if args.object.__type ~= "Player" then return end
	print(tostring(args.object).."'s "..args.key.." was set to "..tostring(args.value))
end
 
Events:Subscribe("NetworkObjectValueChange", Foo)
 
function ConsoleSet(args)
	local words = args.text:split(" ")
 
	if #words == 3 then
		local player = Player.Match(words[1])[1]
		if player then
			player:SetNetworkValue(words[2], words[3])
		else
			print("Player not found!")
		end
	else
		print("Invalid arguments!")
	end
end
 
Console:Subscribe("set", ConsoleSet)

Client

Prints any player value changes to the chat. Used in combination with the server script above.

function Foo(args)
	if args.object.__type ~= "Player" then return end
	Chat:Print(
		tostring(args.object).."'s "..args.key.." was set to "..tostring(args.value),
		Color.Yellow
	)
end
 
Events:Subscribe("NetworkObjectValueChange", Foo)

See also